package com.kyxx.topics.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.kyxx.topics.R;
import com.kyxx.topics.bean.MemberDetailBean;

import java.util.List;

public class MemberShopAdapter extends RecyclerView.Adapter<MemberShopAdapter.ViewHolder>{
    private List<MemberDetailBean.Shop> bean;
    private Context ctx;
    private OnItemClickLitener mOnItemClickLitener;

    public MemberShopAdapter(Context paramContext, List<MemberDetailBean.Shop> paramList){
        this.ctx = paramContext;
        this.bean = paramList;
    }

    public int getItemCount()
    {
        return bean!=null?this.bean.size():0;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        holder.tv_member_shop.setText(bean.get(position).getShop_name());
        holder.tv_member_shop_addr.setText(bean.get(position).getShop_addr());
        // 如果设置了回调，则设置点击事件
        if (mOnItemClickLitener != null)
        {
            holder.itemView.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });
        }
    }

    public ViewHolder onCreateViewHolder(ViewGroup paramViewGroup, int paramInt)
    {
        View localView = LayoutInflater.from(this.ctx).inflate(R.layout.item_member_shop, paramViewGroup, false);
        return new ViewHolder(localView);
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_member_shop_addr;
        TextView tv_member_shop;
        public ViewHolder(View itemView) {
            super(itemView);
            tv_member_shop = (TextView) itemView.findViewById(R.id.tv_member_shop);
            tv_member_shop_addr = (TextView) itemView.findViewById(R.id.tv_member_shop_addr);
        }
    }
    public interface OnItemClickLitener{
        void onItemClick(View view, int position);
    }

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener){
        this.mOnItemClickLitener = mOnItemClickLitener;
    }
}